package com.ctshk.sapp.order.goods.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.goods.dto.CurrentUserOrderCommodityDetailsDTO;
import com.ctshk.rpc.order.goods.dto.OrderDetailDTO;
import com.ctshk.rpc.order.goods.dto.OrderPageListDTO;
import com.ctshk.rpc.order.goods.req.OrderPageListReq;
import com.ctshk.rpc.order.goods.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * TODO
 *
 * @author 黄利斌
 * @date 2021/5/22 4:50 下午
 */
@Slf4j
@Api(value = "中旅到家PC个人中心",tags = "中旅到家PC个人中心")
@RestController
@RequestMapping("/order/commodity/center")
public class OrderCommodityCenterController extends BaseController {

    @DubboReference
    private IOrderService orderService;

    @ApiOperation(value = "个人中心(我的订单)", notes = "个人中心(我的订单)")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "个人中心(我的订单)", operDesc = "个人中心(我的订单)")
    @GetMapping("/orderDetails/{status}")
    public Result<CurrentUserOrderCommodityDetailsDTO> orderDetails(@PathVariable Integer status){
        return null;
    }

    @ApiOperation(value = "PC-订单商品分页列表", notes = "PC订单商品分页列表")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "PC订单商品分页列表", operDesc = "PC订单商品分页列表")
    @PostMapping("/orderCommodityPage")
    public PageResponse<OrderPageListDTO> orderCommodityPage(@RequestBody @Valid OrderPageListReq req ){
        return orderService.orderCommodityPage(req, getCurrentUser(getRequest()).getId());
    }

    @ApiOperation(value = "PC-根据订单ID获取订单详情", notes = "PC-根据订单ID获取订单详情")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "PC-根据订单ID获取订单详情", operDesc = "PC-根据订单ID获取订单详情")
    @GetMapping("/getOrderCommodityDetail/{orderId}/{type}")
    public Result<OrderDetailDTO> getOrderCommodityDetail(@PathVariable("orderId") Long orderId, @PathVariable("type") Integer type){
        TokenUser currentUser = null;
        try {
            currentUser = getCurrentUser(getRequest());
        } catch (Exception e) {
            log.error("【订单详情，未登录】，异常为:{}",e.getMessage());
        }
        OrderDetailDTO resultData = orderService.getAppOrderCommodityDetail(orderId, type, currentUser);
        return Result.success(resultData);
    }
}
